import React, { Component } from 'react'
import GuestGreeting from './guestGreeting'
import UserGreeting from './userGreeting'


export default class condition extends Component {
    constructor(props) {
        super(props);
        this.login = this.login.bind(this);
        this.logout = this.logout.bind(this);
    }
    state = {
        isLogin: false
    }
    login() {
        this.setState({isLogin: true})
    }
    logout() {
        this.setState({isLogin: false})
    }
    render() {
        return (
            <div>
                { this.state.isLogin ? <UserGreeting username="beike"></UserGreeting> : <GuestGreeting></GuestGreeting>  }
            
                { this.state.isLogin ? <button onClick={ this.logout }>注销</button> : <button onClick={ this.login }>登录</button>} 
            </div>
        )
    }
}